﻿/*=========================================================================
 * AUTH: Vincent Breton
 * DESC: Teammate State Machine
 *=========================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RisingThreat
{
    class TeammateStateMachine
    {
        public enum State { FOLLOW, CATCHUP, PATHFIND };

        public State currentState;

        public Teammate agent { get; set; }

        private const float veryBehindRange = 20.0f;
        private const float behindRange = 10.0f;

        private const float closeRange = 2.0f;

        public bool automaticON;

        public TeammateStateMachine(Teammate t)
        {
            agent = t;
            automaticON = true;
            currentState = State.FOLLOW;
        }

        public void update()
        {
            if (automaticON)
                updateAutomatic();
            else
                updateTactical();
        }

        //will follow in formation and shoot enemies it can see if it falls behind it will stop attacking and move back into formation
        public void updateAutomatic()
        {
            if (currentState == State.FOLLOW)
                if ((agent.seek.target - agent.steer.position).Length() > behindRange)
                    currentState = State.CATCHUP;
            if (currentState == State.CATCHUP)
            {   if ((agent.seek.target - agent.steer.position).Length() < closeRange)
                    currentState = State.FOLLOW;
            //if ((agent.seek.target - agent.steer.position).Length() > veryBehindRange)
                //currentState = State.PATHFIND;
            }
            //if (currentState == State.PATHFIND)
                //if ((agent.path.goalPosition - agent.steer.position).Length() < closeRange)
                   // currentState = State.FOLLOW;
        }

        //will act independently using tactical information from waypoint graph (eg. moving to cover, moving to ambush etc.)
        public void updateTactical()
        {

        }

    }
}
